<template>
  <div>
    <el-table :data="userList" stripe style="width: 100%" border>
      <el-table-column prop="id" label="用户编号"></el-table-column>
      <el-table-column prop="username" label="用户名"></el-table-column>
      <el-table-column prop="rolename" label="所属角色"></el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <el-button type="primary" @click="change(scope.row.uid)">编辑</el-button>
          <v-delete @del="del(scope.row.uid)"></v-delete>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="parseInt(userCount)"
      :page-size="5"
      @current-change="next"
    ></el-pagination>
  </div>
</template>
<script>
import { userDel } from "../../../request/api";
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  props: ["user", "flag"],
  computed: {
    ...mapGetters({
      userCount: "manage/userCount",
      userList: "manage/userList",
      userInfo: "manage/userInfo"
    })
  },
  components: {},
  methods: {
    ...mapActions({
      reqUserCount: "manage/reqUserCount",
      reqUserList: "manage/reqUserList",
      reqUserInfo: "manage/reqUserInfo"
    }),
    del(uid) {
      userDel({ uid: uid }).then(res => {
        if (res.data.code == 200) {
          if (this.userList.length == 1 && this.user.page != 1) {
            this.user.page--;
          }
          this.reqUserList(this.user);
          this.reqUserCount();
        }
      });
    },
    next(e) {
      this.user.page = e;
      this.reqUserList(this.user);
    },
    change(uid) {
      this.flag.isShow = true
      this.flag.isAdd = false
      this.reqUserInfo({ uid: uid });
    }
  },
  mounted() {}
};
</script>
<style lang="less" scoped>
</style>